<template>
  <div>
    <el-dialog
      :title="dialogInfo.title"
      :visible.sync="isVisible"
      width="50%"
      @close="closeDialog"
    >
      <span style="text-align: center">
        <slot v-if="dialogInfo.isTransfer">
          <transfer-dialog
            :datas="datas"
            :dialog-info="dialogInfo"
            @returnSelectedResult="returnSelectedResult"
          />
        </slot>
        <slot v-else>
          <alone-dialog :dialog-info="dialogInfo" />
        </slot>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">退出</el-button>
        <!--        进行数据返回-->
        <el-button type="primary" @click="saveResult">保存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import AloneDialog from './AloneDialog'
import TransferDialog from './TransferDialog'
export default {
  name: 'MainDialog',
  components: { TransferDialog, AloneDialog },
  props: {
    dialogInfo: {
      type: Object,
      default: null
    },
    isVisible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      selectedResult: '',
      datas: []
    }
  },
  watch: {
    dialogInfo: {
      handler() {
        if (this.dialogInfo.infoData === 'cyks') {
          this.datas = [
            { key: 1, label: '医生1' },
            { key: 2, label: '医生2' },
            { key: 3, label: '医生3' }]
        } else if (this.dialogInfo.infoData === 'cfks') {
          this.datas = [
            { key: 1, label: '科室1' },
            { key: 2, label: '科室2' },
            { key: 3, label: '科室3' }]
        } else if (this.dialogInfo.infoData === 'zd') {
          this.datas = [
            { key: 1, label: '诊断1' },
            { key: 2, label: '诊断2' },
            { key: 3, label: '诊断3' }]
        } else if (this.dialogInfo.infoData === 'zdyyp') {
          this.datas = [
            { key: 1, label: '自定义药品1' },
            { key: 2, label: '自定义药品2' },
            { key: 3, label: '自定义药品3' }]
        }
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    closeDialog() {
      this.$emit('closeDialog', false)
    },
    returnSelectedResult(result) {
      this.selectedResult = result
    },
    saveResult() {
      this.$emit('selectedResultMain', this.selectedResult)
    }
  }
}
</script>

<style scoped>

</style>
